{extend name="public:layout" /}
{block name="title"}拷贝商品{/block}
{block name="head"}
<script type="text/javascript">var sku_sn = "{:rand_string(8,1)}";</script>
<script type="text/javascript" src="/public/plugins/sku/sku-table.js"></script>
<script type="text/javascript" src="/public/plugins/template/template.js"></script>
<style>
    .dropdown-menu{min-width:65px;}
    .tab-pane{padding-top:10px;}
    .form-control, .single-line{padding:6px 4px;}
</style>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index')}"> 商品列表</a></li>
                <li class="active">编辑商品</li>
            </ol>
        </div>
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form">
                <input type="hidden" name="is_attr" value="{$info.is_attr}"/>
                <input type="hidden" name="cid" value="{$info.cid}"/>
                <ul class="nav nav-tabs" role="tablist">
                    <li role="presentation" class="active">
                        <a href="#base" data-toggle="tab" role="tab">基本信息</a>
                    </li>
                    <li>
                        <a href="#extend" data-toggle="tab" role="tab">扩展信息</a>
                    </li>
                    <li>
                        <a href="#seo" data-toggle="tab" role="tab">SEO选项</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="base">
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" placeholder="请输入商品名称"
                                       name="goods_name" value="{$info.goods_name}" datatype="*"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品副标题</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" placeholder="请输入商品副标题"
                                       name="sub_title" value="{$info.sub_title}"/>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">状态</label>
                            <div class="col-sm-4">
                                <label class="radio-inline i-checks">
                                    <input type="radio" name="is_on_sale" value="1"
                                           {eq name="info.is_on_sale" value="1"}checked{/eq}> 上架
                                </label>
                                <label class="radio-inline i-checks">
                                    <input type="radio" name="is_on_sale" value="0"
                                           {eq name="info.is_on_sale" value="0"}checked{/eq}> 下架
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品类目</label>
                            <div class="col-sm-4">
                                <select class="form-control" id="cid">
                                    <option value="">请选择商品类目</option>
                                    {volist name="goodsCategory" id="vo"}
                                    <option value="{$vo.cid}" {eq name="info.cid" value="$vo['cid']" }selected{/eq}>
                                    {$vo._name}
                                    </option>
                                    {/volist}
                                </select>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">商品品牌</label>
                            <div class="col-sm-4">
                                <select name="brand_id" id="brandId" class="form-control">
                                    <option value="">通用类型</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品分组</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="site_cid">
                                    <option value="">请选择商品分组</option>
                                    {volist name="siteGroup" id="vo"}
                                    <option value="{$vo.cid}" {eq name="info.site_cid" value="$vo['cid']"}selected{/eq}>{$vo._name}</option>
                                    {/volist}
                                </select>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">规格属性</label>
                            <div class="col-sm-3">
                                <select class="form-control" name="attr_id" id="attrId">
                                    <option value="0">普通规格</option>
                                    {volist name="attrList" id="vo"}
                                    <option value="{$vo.attr_id}" {eq name="info.attr_id" value="$vo['attr_id']"}selected{/eq}>{$vo.attr_name}</option>
                                    {/volist}
                                </select>
                            </div>
                            <div class="col-sm-1">
                                <button type="button" class="btn btn-info" onclick="getAttr($('#attrId').val())">重载规格</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">产品相册</label>
                            <div class="col-sm-10">
                                {:widget('common/Form/moreImg',['album',$info['album'],$utype])}
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">推荐商品</label>
                            <div class="col-sm-4">
                                <label class="radio-inline i-checks">
                                    <input type="radio" name="is_commend" value="1" {eq name="info.is_commend" value="1"}checked{/eq} /> 是
                                </label>
                                <label class="radio-inline i-checks">
                                    <input type="radio" name="is_commend" value="0" {eq name="info.is_commend" value="0"}checked{/eq} /> 否
                                </label>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">商品单位</label>
                            <div class="clo-sm-4">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">选择 <span class="caret"></span></button>
                                        <ul class="dropdown-menu dropdown-menu-right">
                                            {volist name="unitList" id="unit"}
                                            <li><a href="javascript:;" onclick="$('#goodsUnit').val('{$unit}')">{$unit}</a></li>
                                            {/volist}
                                        </ul>
                                    </div>
                                    <input type="text" class="form-control" id="goodsUnit" name="goods_unit" value="{$info.goods_unit}"  placeholder="请输入商品单位" />
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品定价</label>
                            <div class="col-sm-10">
                                <div id="attrHtml"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品介绍</label>
                            <div class="col-sm-10">
                                {:widget('common/Form/ueditor',['content',$info['content'],$utype])}
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="extend">
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">库存报警设置</label>
                            <div class="col-sm-1">
                                <input type="text" class="form-control" placeholder="请输入库存报警数量"
                                       name="alert_num" value="{$info.alert_num}" />
                            </div>
                            <div class="col-sm-3">
                                <p class="form-control-static">设置为0不提示</p>
                            </div>
                            <label class="col-sm-2 control-label Validform_label">销售量</label>
                            <div class="col-sm-1">
                                <input type="text" class="form-control" placeholder="请输入销售量"
                                       name="goods_sale_number" value="{$info.goods_sale_number}" />
                            </div>
                            <div class="col-sm-3">
                                <p class="form-control-static">作弊才用，一般不建议修改</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">预售商品</label>
                            <div class="col-sm-4">
                                <label class="radio-inline i-checks">
                                    <input type="radio" name="is_presell" value="1" {eq name="info.is_presell" value="1"}checked{/eq} /> 是
                                </label>
                                <label class="radio-inline i-checks">
                                    <input type="radio" name="is_presell" value="0" {eq name="info.is_presell" value="0"}checked{/eq} /> 否
                                </label>
                            </div>
                            <div id="presell" {eq name="info.is_presell" value="0"}style="display:none;"{/eq}>
                                <label class="col-sm-2 control-label Validform_label">发货日期</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control laydate" name="presell_deliverdate" value="{$info.presell_deliverdate|date='Y-m-d',###}" />
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">基本属性</label>
                            <div class="col-sm-10">
                                {:widget('common/Form/extend',['base_extend',$info['base_extend']])}
                            </div>
                        </div>
                        <!--搜索属性-->
                        <div id="extendHtml"></div>
                    </div>
                    <div class="tab-pane" id="seo">
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品关键词</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" placeholder="请输入商品关键词"
                                       name="keywords" value="{$info.keywords}"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label Validform_label">商品描述</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" name="description" rows="3" placeholder="请输入商品描述">{$info.description}</textarea>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary" type="button" id="btnSub">保存内容</button>
                        <a href="{:url('index')}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        iCheck();
        ajaxSubForm('#btnSub');
        $('#attrId').change(function () {
            var attrId = $(this).val();
            getAttr(attrId);
        });
        //栏目对应品牌和搜索属性
        $("#cid").change(function () {
            var cid = $(this).val();
            getExtend(cid); //搜索html
            getBrand(cid); //品牌选项
        });
        $("#cid").trigger("change"); //加载触发
        $("#attrId").trigger("change"); //加载触发
        $("input[name='is_presell']").on('ifChecked', function (event) {
            if($(this).val()==1){
                $('#presell').show();
            }else{
                $('#presell').hide();
            }
        });
    })

    /**
     * 获取栏目绑定属性
     */
    function getAttr(attrId) {
        getAjax('{:url("getAttr")}', {attr_id: attrId}, function (html) {
            if(html!=''){
                $('#attrHtml').html(html);
            }else{
                $('#attrHtml').html('');
            }
        })
    }
    /**
     * 获取指定栏目下对应品牌
     * @param cid
     */
    function getBrand(cid) {
        var InfoBrandId = "{$info.brand_id}";
        getAjax('{:url("getCidBrand")}', {cid: cid}, function (res) {
            $("#brandId").empty();
            if (res.length > 0) {
                $('#brandId').append('<option value="">请选择商品品牌</option>');
                for (var i = 0; i < res.length; i++) {
                    var selected = '';
                    if (InfoBrandId == res[i].brand_id) {
                        selected = 'selected';
                    }
                    $('#brandId').append('<option value="' + res[i].brand_id + '" ' + selected + '>' + res[i].brand_name + '</option>');
                }
            }
        })
    }
    /**
     * 获取指定类目下搜索属性
     * @param extendId
     */
    function getExtend(cid) {
        if(cid>0){
            getAjax('{:url("extend")}',{cid:cid},function(html){
                $('#extendHtml').html(html);
            })
        }else{
            $('#extendHtml').empty();
        }
    }
</script>
{/block}